//
//  AppDelegate.swift
//  SinaWeibo
//
//  Created by 李江波 on 2016/11/12.
//  Copyright © 2016年 lijiangbo. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        changeRootViewController()
        
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.backgroundColor = UIColor.white
        
        window?.rootViewController = LEEOAuthViewModel.shared.isLogin ? LEEWelcomeController() : LEETabController()
        
        window?.makeKeyAndVisible()
        
        return true
    }

    /// 改变根视图
    private func changeRootViewController() {
        
        NotificationCenter.default.addObserver(self, selector: #selector(changeVc), name: NSNotification.Name(rawValue: ChangeRootViewController), object: nil)
        
    }
    
    func changeVc(notifi : Notification) {
        
        let vc : String = notifi.object as! String
        
        switch vc {
        case "welcomeVc":
            
            UIApplication.shared.keyWindow?.rootViewController = LEEWelcomeController()
        default:
            
            UIApplication.shared.keyWindow?.rootViewController = LEETabController()
        }
    }
    
    func applicationDidEnterBackground(_ application: UIApplication) {
        //清除缓存
        LEEStatusetDAL.deleteCacheStatuses()
    }

}

